package com.leslie.app.controller;

import com.leslie.app.constant.Enums;
import com.leslie.app.dto.StreamInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/stream")
public class StreamDemo {
    @RequestMapping("/to-list")
    public List<String> streamToList() {
        Stream<String> stream = Stream.of("Leslie", "Tom", "Ron", "April", "Andy");
        return stream.collect(Collectors.toList());
    }

    @RequestMapping("to-map")
    public StreamInfo streamToMap() {
        List<String> list = List.of("Leslie", "Tom", "Ron", "April", "Andy");
        Stream<String> stream = list.stream();
        String message = "This is a stream of names";
        return new StreamInfo(stream, message);
    }

    @RequestMapping("any-match")
    public boolean streamAnyMatch() {

        List<String> list = List.of("STAFF1","EMPLOYEE","GUEST");
        Stream<String> stream = list.stream();
        return stream.anyMatch(Enums.PASSENGER_SEGMENT_FLAG.STAFF.name()::equals);
    }
}
